<script setup>
import {computed, inject, provide, ref, watch} from "vue";
import workOrder from '@/api/logistics/workOrder'
import BaseInfo from "./components/baseInfo.vue";
import BaseLog from "./components/log.vue";
import Attachment from "@/views/components/attachment.vue";
import OperateInfo from "@/views/components/operateInfo.vue";
import { auth, role } from '@/utils/common'
const record = ref({})
const visible = ref(false)
const crudRef = inject('crudRef')
const fileData = ref({type:6,span:{ xs: 1, sm: 3}})

const open = async (data) => {
  record.value = data
  visible.value = true
}

const refreshRecode = async (type) => {
  if(record.value.id == undefined){
    return;
  }
  console.log('刷新详情')
  let request = await workOrder.read(record.value.id)
  record.value = request.data
  if(type == true){
    console.log('刷新列表')
    crudRef.value.refresh()
  }
}

const colGap = ref(6)
const rowGap = ref(6)
provide('colGap', colGap)
provide('rowGap', rowGap)
provide('record', record)
provide('refreshRecode', refreshRecode)
provide('fileData', fileData)
defineExpose({ open,refreshRecode })
</script>
<template>
    <a-drawer v-model:visible="visible" width="80%" :footer="false">
      <template #title>
        <div class="grid grid-cols-[minmax(0,1fr),auto] items-center">
          <div>工单#{{ record.title }}</div>
        </div>
      </template>
        <a-space direction="vertical" class="w-full">
          <a-grid :cols="{ xs: 1, sm: 2, md: 3, lg: 4, xxl: 6 }" :colGap="colGap" :rowGap="rowGap">
            <base-info />
            <base-log />
            <OperateInfo />
            <attachment v-if="auth('document:attachment:index')" />
          </a-grid>
        </a-space>
    </a-drawer>
  </template>



